import turtle

turtle.speed(0)
turtle.ht()

def calculate_chars_per_line(text, window_width):
    return int(window_width / 8)

def split_text(text, chars_per_line):
    return [text[i:i+chars_per_line] for i in range(0, len(text), chars_per_line)]

lines_num = 0
def draw_text(text, x, y):
    global lines_num
    window_width = 449  
    chars_per_line = calculate_chars_per_line(text, window_width)
    lines = split_text(text, chars_per_line)
    lines_num = len(lines)
    y = lines_num*25/2
    for line in lines:
        turtle.penup()
        turtle.goto(x,y)
        turtle.write(line, align="center",font=('courier',16))
        y -= 25
    return lines_num

fxn = turtle
layer = 1
former = [fxn]
def change_layers(respond):
    global layer
    global fxn
    global former
    if respond == 'backpage':
        if layer==1:
            print('已经是第一层了')
        else:
            layer -= 1
            fxn = former[layer-1]
            former.pop()
    else:
        if respond in dir(fxn):
            layer += 1
            fxn = getattr(fxn,respond)
            former.append(fxn)
        else:
			print('未找到指定函数')

while True:
    turtle.clear()
    list = dir(fxn)
    text = ','.join(list)
    draw_text(text, 0, 0)
    print('正在查看',fxn,'的内置函数')
    print(list)
    turtle.done()
    change_layers(input('键入以查看内置函数功能（区分大小写）退回上一级请输入\'backpage\''))